package permission

import (
	"time"
)

// Permission 权限实体
type Permission struct {
	ID          string    `bson:"_id,omitempty"`
	Name        string    `bson:"name"`
	Description string    `bson:"description"`
	Resource    string    `bson:"resource"`
	Action      string    `bson:"action"`
	CreatedAt   time.Time `bson:"created_at"`
	UpdatedAt   time.Time `bson:"updated_at"`
}

// NewPermission 创建新权限
func NewPermission(name, description, resource, action string) *Permission {
	now := time.Now()
	return &Permission{
		Name:        name,
		Description: description,
		Resource:    resource,
		Action:      action,
		CreatedAt:   now,
		UpdatedAt:   now,
	}
}

// Update 更新权限信息
func (p *Permission) Update(name, description, resource, action string) {
	p.Name = name
	p.Description = description
	p.Resource = resource
	p.Action = action
	p.UpdatedAt = time.Now()
}